package 尊享面试.哈希;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class a734句子相似性 {
    static class Solution {
        public boolean areSentencesSimilar(String[] sentence1, String[] sentence2, List<List<String>> similarPairs) {
            if(sentence1.length != sentence2.length){
                return false;
            }
            HashSet<String>pair = new HashSet<>();
            for (List<String> similarPair : similarPairs) {
                pair.add(similarPair.get(0)+"#"+similarPair.get(1));
            }
            for (int i = 0; i < sentence1.length; i++) {
                if(!sentence1[i].equals(sentence2[i])
                    &&!pair.contains(sentence1[i]+"#"+sentence2[i])
                        &&!pair.contains(sentence2[i]+"#"+sentence1[i])
                ){
                    return false;
                }
            }
            return true;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] sentence1 = {"great", "acting", "skills"};
        String[] sentence2 = {"fine", "drama", "talent"};
        List<List<String>>similarPairs = new ArrayList<>();
        similarPairs.add(Arrays.asList("great","fine"));
        similarPairs.add(Arrays.asList("drama","acting"));
        similarPairs.add(Arrays.asList("skills","talent"));
        System.out.println(solution.areSentencesSimilar(sentence1, sentence2, similarPairs));
    }
}
